﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ReadXml
{
    class TrainData
    {
        public void trainData(ref  List<List<List<double>>> trainarray, ref List<List<List<double>>> testarray, ref List<string> trainclassarray, ref List<string> classnames, ref List<string>testclassarray)
        {
            // int[] n = {1,2,3,4,5,6,7,8,9};
            /***** 读入训练集和测试集 *****/

            
            int[] p = { 0, 30, -30, 60, -60, 90, -90 };


            string[] names = Directory.GetDirectories(@"C:\毕设\数据\3m\0\");
            foreach (string name in names)
            {
                classnames.Add(Path.GetFileName(name));
            }
            for (int j = 0; j < 7; j++)
            {
                string[] folders = Directory.GetDirectories(@"C:\毕设\数据\3m\" + p[j].ToString() + @"\");
                string[] folderNames = new string[folders.Length];
                for (int i = 0; i < folders.Length; i++)
                {
                    folderNames[i] = Path.GetFileName(folders[i]);
                }
                for (int m = 0; m < folders.Length; m++)
                {
                    string[] files = Directory.GetFiles(@"C:\毕设\数据\3m\" + p[j].ToString() + @"\" + folderNames[m] + @"\");
                    string[] fileNums = new string[files.Length];
                    for (int i = 0; i < files.Length; i++)
                    {
                        fileNums[i] = Path.GetFileName(files[i]);
                    }
                    double middlePoint = files.Length / 2.0;
                    middlePoint = Math.Ceiling(middlePoint);
                    for (int k = 0; k < middlePoint; k++)
                    {
                        string url1 = @"C:\毕设\数据\3m\" + p[j].ToString() + @"\" + folderNames[m] + @"\" + fileNums[k].ToString();
                        var data = (new GetXml()).getXml(url1);
                        trainarray.Add(data);
                        trainclassarray.Add(folderNames[m]);
                    }
                    for (int k = Convert.ToInt16(middlePoint); k < files.Length; k++)
                    {
                        string url2 = @"C:\毕设\数据\3m\" + p[j].ToString() + @"\" + folderNames[m].ToString() + @"\" + fileNums[k].ToString();
                        var data = (new GetXml()).getXml(url2);
                        testarray.Add(data);
                        testclassarray.Add(folderNames[m]);
                    }
                }
            }
        }    

    }
}
